#include "Thread.h"

CThread::CThread() :
m_threadStatus(EM_THREAD_FREE),
m_iErrorCode(0),
m_strThreadName(""),
m_iThreadID(0),
m_iPriority(0),
m_bExit(false)
{
}

CThread::~CThread()
{
	::CloseHandle(m_handle);
}

bool CThread::Terminate()
{
	_endthreadex(0);

	return true;
}

bool CThread::Start()
{
	DWORD dwFlags = 0;
	unsigned int  uiThreadID = 0;


	m_threadStatus = EM_THREAD_RUN;

	m_handle = (HANDLE)_beginthreadex(NULL, 0, ThreadFunction, this, dwFlags, &uiThreadID);
	m_iThreadID = uiThreadID;

	return true;
}

unsigned int __stdcall CThread::ThreadFunction(void * lpParam)
{
	CThread *pThread = (CThread *)lpParam;

	pThread->Run();
	return 0;
}
